public  gps_rmc_parse

ss3      segment     code
rseg    ss3


extrn   code(write_com)    ;;;
extrn   code(write_data)   ;;;
extrn   code(put_str)
extrn   code(send_sms)
extrn   code(status_check)
extrn   code(get_comma_string)
extrn   code(get_second_mul)
extrn   code(anal_temper)


time_or_locat   bit     20h.5
gps_dat_vaild   bit     20h.6
lati_or_longti  bit     20h.7

one_lati        equ     40h
mten_lati       equ     41h
mone_lati       equ     42h


cxpos   equ     21h
cypos   equ     22h
str_loca_sms    equ     33h
comma_start     equ     35h
comma_content_size  equ 36h
comma_res_start equ     37h
which_comma     equ     38h


rev_buffer      equ     46h
tmp             equ     48h



;---------------------------------------------------------------------------
gps_rmc_parse:
    push    1
    mov     a,55h                    ;$GPRMC, MCU saves 'C' in 55h
    
    cjne    a,#43h,exit_gps_rmc_parse                     ;43h='C' in asscii
    mov     a,#01h
    call    write_com
   
checking:
    call    status_check
    jnb     gps_dat_vaild,warning_gps_rmc_parse
    clr     gps_dat_vaild
    jnb     time_or_locat,disp_time
    clr     time_or_locat
    call    get_location
    lcall    DEL1S
    lcall    DEL1S
    lcall    DEL1S
   
    lcall    anal_temper
    lcall    DEL1S
    lcall    DEL1S
    lcall    DEL1S
    
    ;;lcall    send_sms        ;;;;;
    
    sjmp    exit_gps_rmc_parse
disp_time:
    call    get_time
    setb    time_or_locat
    lcall    DEL1S
    lcall    DEL1S
    lcall    DEL1S
   
    sjmp    exit_gps_rmc_parse
    

    
warning_gps_rmc_parse:
    mov     cxpos,#00h
    mov     cypos,#00h
    mov     dptr,#table2
    call    put_str

    mov     cxpos,#00h
    mov     cypos,#01h
    mov     dptr,#table3
    call    put_str



exit_gps_rmc_parse:
    pop     1
    ret




;------------------------------------------------------------------------   
get_location:
    mov     a,#01h
    lcall   write_com
    call    get_latitude 
    call    get_longitude
    ret
;------------------------------------------------------------------------   

;------------------------------------------------------------------------   
get_time:
    push    1
    mov     a,#01h
    call    write_com

    mov     cxpos,#00h
    mov     cypos,#00h
    mov     dptr,#table4
    call    put_str

    mov     a,#0c0h
    call    write_com

    mov     comma_start, rev_buffer
    mov     which_comma,#01h
    mov     comma_content_size,#00h
    call    get_comma_string
    mov     r1,comma_res_start
hour_get_time:
    
    mov     a,@r1   
    inc     r1
    call    write_data
    mov     a,@r1   
    inc     r1
    call    write_data
    mov     a,#68h
    call    write_data      ;68h='h'
minute_get_time:
    mov     a,@r1
    inc     r1
    call    write_data
    mov     a,@r1
    inc     r1
    call    write_data
    mov     a,#6dh
    call    write_data      ;6dh='m'
second_get_time:
    mov     a,@r1
    inc     r1
    call    write_data
    mov     a,@r1
    inc     r1
    call    write_data
    mov     a,#73h
    call    write_data      ;73h='m'


exit_get_time:
    pop     1
    ret  
;------------------------------------------------------------------------       
/*
;------------------------------------------------------------------------
gps_timer_10s:
    push    1
    mov     tmp,#00h

    mov     comma_start, rev_buffer
    mov     which_comma,#01h
    mov     comma_content_size,#00h
    call    get_comma_string
    mov     a,comma_res_start
    add     a,#04h
    mov     r1,a
    mov     a,@r1
    cjne    a,#35h,next0_gps_timer_10s


next0_gps_timer_10s:
    mov     tmp,a




     



exit_gps_timer_10s:
    pop     1
    ret
    



;------------------------------------------------------------------------ 
*/









;---------------------------------------------------------------------
;input: None
;output: Tht output will be like like (ten_lati)(one_lati).(mten_lati)(mone_lati).(sten_lati)(sone_lati)
;effect: r1


get_latitude: 
    push    1
    
    mov     comma_start, rev_buffer
    mov     which_comma,#03h
    mov     comma_content_size,#00h
    call    get_comma_string

    
    mov     which_comma,#04h
    call    display_lati_or_longti

    

    pop     1
    ret

;-------------------------------------------------------------------------------

;---------------------------------------------------------------------
;input: None
;output: Tht output will be like like (ten_lati)(one_lati).(mten_lati)(mone_lati).(sten_lati)(sone_lati)
;effect: r1


get_longitude: 
    push    1
    
    mov     comma_start, rev_buffer
    mov     which_comma,#05h
    mov     comma_content_size,#00h
    call    get_comma_string

    
    mov     which_comma,#06h
    mov     a,#0c0h
    call    write_com
    call    display_lati_or_longti

    

    pop     1
    ret

;-------------------------------------------------------------------------------




;-------------------------------------------------------------------------------
;input: dptr,which_comma
;effect: r7
display_lati_or_longti:
    push    1
    push    0
    ;mov     r0,str_loca_sms
    mov     r7,#00h
   
    mov     r1,comma_res_start
    jb      lati_or_longti,display_increase
    setb    lati_or_longti
    mov     r0,str_loca_sms
    sjmp    loop2_display_lati_or_longti

display_increase:
    inc     r1
    mov     r0,str_loca_sms
    mov     str_loca_sms,#0e0h       ;get back the init value
    clr     lati_or_longti
loop2_display_lati_or_longti:

    mov     a,@r1
    movx    @r0,a          ;;
    inc     r0            ;;
            
    call    write_data
    inc     r1
    inc     r7
    cjne    r7,#02h,loop2_display_lati_or_longti
    mov     a,#64h
    movx    @r0,a          ;;
    inc     r0             ;;
    call    write_data         ;64h=d(degree) 
loop3_display_lati_or_longti:    
    mov     a,@r1
    movx    @r0,a          ;;
    inc     r0             ;;
    call    write_data
    inc     r1
    inc     r7
    cjne    r7,#04h,loop3_display_lati_or_longti
    mov     a,#6dh             ;6d=m(Minute)
    movx    @r0,a          ;;
    inc     r0             ;;
    call    write_data
loop4_display_lati_or_longti: 
    
    inc     r1                 ;for skipping the symbol '.'
    
    call    get_second_mul
    mov     a,r2
    movx    @r0,a          ;;
    inc     r0             ;;
    call    write_data
    mov     a,r3
    movx    @r0,a          ;;
    inc     r0             ;;
    call    write_data
    mov     a,#2eh
    movx    @r0,a          ;;
    inc     r0             ;;
    call    write_data        ;2eh='.'
    mov     a,r4
    movx    @r0,a          ;;
    inc     r0             ;;
    call    write_data
       
    mov     a,#73h             ;73h=s(Second)
    movx    @r0,a          ;;
    inc     r0             ;;
    call    write_data
    
    mov     comma_start, rev_buffer
    mov     comma_content_size,#00h
    call    get_comma_string 
    
    mov     r1,comma_res_start
    mov     a,@r1
    movx    @r0,a          ;;
    inc     r0             ;;
    call    write_data

    


    jnb     lati_or_longti,exit_display_lati_or_longti
    
    mov     a,#0ah
    movx     @r0,a                   ;we need use movx
    inc     r0
    mov     str_loca_sms,r0
exit_display_lati_or_longti:
    
    
    pop     0
    pop     1
    ret
;---------------------------------------------------------------------------

DEL1S:MOV R7,#10
D1:   MOV R6,#200
D2:   MOV R5,#250
      DJNZ R5,$
      DJNZ R6,D2
      DJNZ R7,D1
      RET
    
    




;---------------------------------------------------------------------------






table2:     db      "Searching...",00h
table3:     db      "Waiting response",00h
table4:     db      "Current time:",00h

end  